home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_300
/
334_02
/
latex.trm
< prev
next >
Wrap
Text File
|
1991-02-04
|
18KB
|
639 lines
/* GNUPLOT - latex.trm */
/*
* Copyright (C) 1990
*
* Permission to use, copy, and distribute this software and its
* documentation for any purpose with or without fee is hereby granted,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
*
* Permission to modify the software is granted, but not the right to
* distribute the modified code. Modifications are to be distributed
* as patches to released version.
*
* This software is provided "as is" without express or implied warranty.
*
* This file is included by ../term.c.
*
* This terminal driver supports:
* LaTeX pictures (latex).
* LaTeX pictures with emTeX specials (emtex).
*
* AUTHORS
* David Kotz, Russell Lang
*
* send your comments or suggestions to (pixar!info-gnuplot@sun.com).
*
*/
/* modified to optimize use of \rule for long lines */
/* the following LATEX driver has been modified by
Russell Lang, eln272v@monu1.cc.monash.oz from the
GnuTeX 1.3 driver by David Kotz, dfk@cs.duke.edu
And further extended by David Kotz */
#define LATEX_PTS_PER_INCH (72.27)
#define DOTS_PER_INCH (300) /* resolution of printer we expect to use */
#define LATEX_UNIT (LATEX_PTS_PER_INCH/DOTS_PER_INCH) /* dot size in pt */
/* 5 inches wide by 3 inches high (default) */
#define LATEX_XMAX (5*DOTS_PER_INCH) /* (LATEX_PTS_PER_INCH/LATEX_UNIT*5.0) */
#define LATEX_YMAX (3*DOTS_PER_INCH) /* (LATEX_PTS_PER_INCH/LATEX_UNIT*3.0) */
#define LATEX_HTIC (5*DOTS_PER_INCH/72) /* (5./LATEX_UNIT) */
#define LATEX_VTIC (5*DOTS_PER_INCH/72) /* (5./LATEX_UNIT) */
#define LATEX_HCHAR (DOTS_PER_INCH*53/10/72) /* (5.3/LATEX_UNIT) */
#define LATEX_VCHAR (DOTS_PER_INCH*11/72) /* (11./LATEX_UNIT) */
static int LATEX_posx;
static int LATEX_posy;
enum JUSTIFY latex_justify=LEFT;
static int latex_angle=0;
/* Default line-drawing character */
/* the definition of plotpoint varies with linetype */
#define LATEX_DOT "\\usebox{\\plotpoint}"
#define LATEX_TINY_DOT "\\rule{.1pt}{.1pt}" /* for dots plot style */
/* POINTS */
#define LATEX_POINT_TYPES 12 /* we supply more point types */
static char *LATEX_points[] = {
"\\raisebox{-1.2pt}{\\makebox(0,0){$\\Diamond$}}",
"\\makebox(0,0){$+$}",
"\\raisebox{-1.2pt}{\\makebox(0,0){$\\Box$}}",
"\\makebox(0,0){$\\times$}",
"\\makebox(0,0){$\\triangle$}",
"\\makebox(0,0){$\\star$}",
"\\circle{12}", "\\circle{18}", "\\circle{24}",
"\\circle*{12}", "\\circle*{18}", "\\circle*{24}"
};
/* LINES */
static int LATEX_type; /* negative types use real lines */
#define LATEX_LINE_TYPES 6 /* number of line types below */
#define LATEX_THIN_LINE 0 /* the thinnest solid line type */
static struct {
float size; /* size of dot, or thick of line in points */
float dotspace; /* inter-dot space in points; 0 for lines */
} LATEX_lines[] = {
{.4, 0.0}, /* thin solid line */
{1.0, 0.0}, /* thick solid line */
{2.0, 0.0}, /* Thick solid line */
{.4, 5.0}, /* dotted line */
{.4, 10.0}, /* widely dotted line */
{.4, 15.0} /* really widely dotted line */
};
/* for drawing dotted and solid lines */
static void LATEX_dot_line();
static void LATEX_solid_line();
static void LATEX_rule();
#define LATEX_flushrule() LATEX_rule(2, 0.,0.,0.,0.) /* flush old rule */
static BOOLEAN LATEX_moved = TRUE; /* pen is up after move */
static float LATEX_dotsize; /* size of LATEX_DOT in units */
#ifdef EMTEX
BOOLEAN emtex=FALSE; /* not currently using emtex */
static void EMTEX_solid_line();
#endif
/* ARROWS */
/* the set of non-vertical/non-horizontal LaTeX vector slopes */
/* except negatives - they are handled specially */
static struct vslope {
int dx, dy;
} LATEX_slopes[] = {
{1,1}, {1,2}, {1,3}, {1,4},
{2,1}, {2,3},
{3,1}, {3,2}, {3,4},
{4,1}, {4,3},
{0,0} /* terminator */
};
static void best_latex_arrow(); /* figure out the best arrow */
LATEX_init()
{
#ifdef EMTEX
emtex = FALSE;
#endif
LATEX_posx = LATEX_posy = 0;
LATEX_linetype(-1);
fprintf(outfile, "%% GNUPLOT: LaTeX picture\n");
fprintf(outfile, "\\setlength{\\unitlength}{%fpt}\n", LATEX_UNIT);
}
LATEX_scale(xs, ys)
float xs, ys; /* scaling factors */
{
register struct termentry *t = &term_tbl[term];
/* we change the table for use in graphics.c and LATEX_graphics */
t->xmax = (unsigned int)(LATEX_XMAX * xs);
t->ymax = (unsigned int)(LATEX_YMAX * ys);
return(TRUE);
}
LATEX_graphics()
{
register struct termentry *t = &term_tbl[term];
fprintf(outfile, "\\begin{picture}(%d,%d)(0,0)\n", t->xmax, t->ymax);
fprintf(outfile, "\\tenrm\n");
fprintf(outfile,
"\\ifx\\plotpoint\\undefined\\newsavebox{\\plotpoint}\\fi\n");
}
LATEX_text()
{
LATEX_flushrule();
fprintf(outfile, "\\end{picture}\n");
}
LATEX_linetype(linetype)
int linetype;
{
if (linetype >= LATEX_LINE_TYPES)
linetype %= LATEX_LINE_TYPES;
#ifdef EMTEX
if (!emtex)
#endif
LATEX_flushrule();
if (linetype >= 0 &&
(LATEX_type < 0 ||
LATEX_lines[linetype].size != LATEX_lines[LATEX_type].size)) {
/* redefine \plotpoint */
fprintf(outfile,
"\\sbox{\\plotpoint}{\\rule[%.3fpt]{%.3fpt}{%.3fpt}}%%\n",
-LATEX_lines[linetype].size/2,
LATEX_lines[linetype].size,
LATEX_lines[linetype].size);
#ifdef EMTEX
if (emtex) /* change line width */
fprintf(outfile, "\\special{em:linewidth %.1fpt}%%\n",
LATEX_lines[linetype].size);
#endif
}
LATEX_type = linetype;
LATEX_dotsize
= ((linetype >= 0) ? LATEX_lines[linetype].size / LATEX_UNIT : 0);
LATEX_moved = TRUE; /* reset */
}
LATEX_move(x,y)
unsigned int x,y;
{
LATEX_posx = x;
LATEX_posy = y;
LATEX_moved = TRUE; /* reset */
}
LATEX_point(x,y, number) /* version of line_and_point */
unsigned int x,y;
int number; /* type of point */
{
LATEX_move(x,y);
/* Print the character defined by 'number'; number < 0 means
to use a dot, otherwise one of the defined points. */
fprintf(outfile, "\\put(%d,%d){%s}\n", x, y,
(number < 0 ? LATEX_TINY_DOT
: LATEX_points[number % LATEX_POINT_TYPES]));
}
LATEX_vector(ux,uy)
unsigned int ux,uy;
{
/* Negative linestyles are straight lines for frame and axes. */
/* These are vertical and horizontal lines only. */
if (LATEX_type < 0) {
int x=ux, y=uy;
if (x == LATEX_posx) { /* vertical */
fprintf(outfile, "\\put(%d,%d){\\line(0,%d){%d}}\n",
LATEX_posx, LATEX_posy,
sign(y - LATEX_posy), abs(y - LATEX_posy));
} else if (y == LATEX_posy) { /* horizontal */
fprintf(outfile, "\\put(%d,%d){\\line(%d,0){%d}}\n",
LATEX_posx, LATEX_posy,
sign(x - LATEX_posx), abs(x - LATEX_posx));
}
} else { /* drawing real curves */
if (LATEX_lines[LATEX_type].dotspace == 0.0)
#ifdef EMTEX
if (emtex)
EMTEX_solid_line(LATEX_posx, (int)ux, LATEX_posy, (int)uy);
else
#endif
LATEX_solid_line(LATEX_posx, (int)ux, LATEX_posy, (int)uy);
else
LATEX_dot_line(LATEX_posx, (int)ux, LATEX_posy, (int)uy);
}
LATEX_posx = ux;
LATEX_posy = uy;
}
static void
LATEX_solid_line(x1,x2, y1,y2)
int x1,x2, y1,y2;
{
float slope;
int inc;
float next;
float x,y;
int code; /* possibly combine with previous rule */
/* we draw a solid line using the thickness for this linetype */
/* we do it with lots of \\rules */
if (x1 == x2 && y1 == y2) { /* zero-length line - just a dot */
if (LATEX_moved) {
LATEX_flushrule();
/* plot a dot */
fprintf(outfile, "\\put(%u,%u){%s}\n", x1, y1, LATEX_DOT);
}
} else {
code = (LATEX_moved ? 0 : 1); /* no combine after move */
if (x1 == x2) /* vertical line - special case */
LATEX_rule(code, (float)x1, (float)y1, LATEX_dotsize, (float)y2-y1)